package com.shujia.java.day13.demo3;

import com.shujia.java.day13.demo2.Phone;
import javafx.beans.binding.ObjectExpression;

import java.util.HashSet;
import java.util.Iterator;

/**
 * Iterator遍历对象
 */
public class IteratorTest1 {
    public static void main(String[] args) {
        //创建集合
        HashSet hashSet = new HashSet();
        //创建对象
        Phone phone1 = new Phone("华为",3000,"P20");
        Phone phone2 = new Phone("苹果",6000,"X");
        Phone phone3 = new Phone("苹果",12000,"MAX X");

        hashSet.add(phone1);
        hashSet.add(phone2);
        hashSet.add(phone3);
        //创建迭代器
        Iterator i =hashSet.iterator();
        //迭代器遍历
        while(i.hasNext()){
            //需不需要转型？需要转型
            Object o=i.next();//next返回值Object
            Phone p = (Phone) o;
            System.out.println(p.getType());
        }
    }
}
